﻿package com.greensock.plugins
{
    import com.greensock.*;

    public class DynamicPropsPlugin extends TweenPlugin
    {
        protected var _target:Object;
        protected var _props:Array;
        protected var _lastFactor:Number;
        public static const API:Number = 1;

        public function DynamicPropsPlugin()
        {
            this.propName = "dynamicProps";
            this.overwriteProps = [];
            this._props = [];
            return;
        }// end function

        override public function onInitTween(param1:Object, param2, param3:TweenLite) : Boolean
        {
            var _loc_5:String = null;
            this._target = param3.target;
            var _loc_4:* = param2.params || {};
            this._lastFactor = 0;
            for (_loc_5 in param2)
            {
                
                if (_loc_5 != "params")
                {
                    this._props[this._props.length] = new DynamicProperty(_loc_5, param2[_loc_5] as Function, _loc_4[_loc_5]);
                    this.overwriteProps[this.overwriteProps.length] = _loc_5;
                }
            }
            return true;
        }// end function

        override public function killProps(param1:Object) : void
        {
            var _loc_2:* = this._props.length;
            while (_loc_2--)
            {
                
                if (this._props[_loc_2].name in param1)
                {
                    this._props.splice(_loc_2, 1);
                }
            }
            super.killProps(param1);
            return;
        }// end function

        override public function set changeFactor(param1:Number) : void
        {
            var _loc_2:int = 0;
            var _loc_3:DynamicProperty = null;
            var _loc_4:Number = NaN;
            var _loc_5:Number = NaN;
            if (param1 != this._lastFactor)
            {
                _loc_2 = this._props.length;
                _loc_5 = param1 == 1 || this._lastFactor == 1 ? (0) : (1 - (param1 - this._lastFactor) / (1 - this._lastFactor));
                while (_loc_2--)
                {
                    
                    _loc_3 = this._props[_loc_2];
                    _loc_4 = _loc_3.params ? (_loc_3.getter.apply(null, _loc_3.params)) : (_loc_3.getter());
                    this._target[_loc_3.name] = _loc_4 - (_loc_4 - this._target[_loc_3.name]) * _loc_5;
                }
                this._lastFactor = param1;
            }
            return;
        }// end function

    }
}

class DynamicProperty extends Object
{
    public var name:String;
    public var getter:Function;
    public var params:Array;

    function DynamicProperty(param1:String, param2:Function, param3:Array)
    {
        this.name = param1;
        this.getter = param2;
        this.params = param3;
        return;
    }// end function

}

